//
//  DDOpenAccountViewController.m
//  LYJR_XDD
//
//  Created by 肖棟棟 on 16/8/6.
//  Copyright © 2016年 肖棟棟. All rights reserved.
//

#import "DDOpenAccountViewController.h"
#import "DDOpenDetailViewController.h"
#import "DDAgreeLb.h"
#import "DDAgreeViewController.h"

@interface DDOpenAccountViewController ()

//手机号view
@property (nonatomic, strong) UIView *phoneView;
@property (nonatomic, strong) UITextField *loginPhoneTextField;

//开户按钮
@property (nonatomic, strong) UIButton *openAccountBtn;

@property (nonatomic, strong) UILabel *registerLb;
//用户服务协议
@property (nonatomic, strong) DDAgreeLb *agreeLb;



@end

@implementation DDOpenAccountViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view
    self.view.backgroundColor = DDBgColor;
    self.title = @"开户";
    self.navigationController.navigationBar.backgroundColor = [UIColor redColor];
    
    //隐藏上方的导航条
    //    [self.navigationController setNavigationBarHidden:YES animated:YES];
    [self createUI];
    [self setNavButton];
}

-(void)setNavButton{
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"Group 51"] style:UIBarButtonItemStylePlain target:self action:@selector(backBtnDidClick)];
}

-(void)backBtnDidClick{

    [self.navigationController popViewControllerAnimated:YES];
}

-(void)createUI{
    
    UIImageView *phoneImageView = [[UIImageView alloc]init];
    phoneImageView.image = [UIImage imageNamed:@"Group 1"];
    
    
    UIImageView *bottomImageView = [[UIImageView alloc]init];
    bottomImageView.image = [UIImage imageNamed:@"Rectangle 137"];
    
    
    [self.view addSubview:self.phoneView];
    [self.phoneView addSubview:phoneImageView];
    [self.phoneView addSubview:self.loginPhoneTextField];
    [self.view addSubview:self.openAccountBtn];
    [self.view addSubview:self.registerLb];
    [self.view addSubview:self.agreeLb];
    [self.view addSubview:bottomImageView];
    
    typeof(self) weakSelf = self;
    
    //执行点击用户服务协议
    _agreeLb.myBlock = ^{
//        
        DDAgreeViewController * agVc = [[DDAgreeViewController alloc] init];
 
        [weakSelf.navigationController pushViewController:agVc animated:YES];
        
    };
    
    //约束
    [_phoneView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.view).offset(89);
        make.left.mas_equalTo(self.view).offset(15);
        make.right.mas_equalTo(self.view).offset(-15);
        make.height.mas_equalTo(50);
    }];
    [phoneImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_phoneView).offset(12);
        make.bottom.mas_equalTo(_phoneView).offset(-12);
        make.left.mas_equalTo(_phoneView).offset(10);
        make.width.mas_equalTo(phoneImageView.mas_height);
    }];
    
    [_loginPhoneTextField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.mas_equalTo(phoneImageView);
        make.left.mas_equalTo(phoneImageView.mas_right).offset(10);
        make.right.mas_equalTo(_phoneView);
    }];
    
    [_openAccountBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_phoneView.mas_bottom).offset(25);
        make.left.right.height.mas_equalTo(_phoneView);
    }];
    
    [_registerLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_openAccountBtn.mas_bottom).offset(15);
        make.left.mas_equalTo(_openAccountBtn);
    }];
    
    [_agreeLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(_registerLb);
        make.left.mas_equalTo(_registerLb.mas_right);
    }];
    
    
    [bottomImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(self.view).offset(-75/2);
        make.left.right.mas_equalTo(self.view);
        //此时图片大小为自己假定
        make.height.mas_offset(494/2);
    }];
    
    
}

#pragma mark - 私有方法
-(void)openAccountBtnDidClick{
    NSLog(@"开户");
    
    DDOpenDetailViewController* openDtVc = [[DDOpenDetailViewController alloc] init];
    openDtVc.title = @"开户";
    openDtVc.phoneNum = self.loginPhoneTextField.text;
    [self.navigationController pushViewController:openDtVc animated:YES];
}


#pragma mark - 懒加载

-(UIView *)phoneView{
    if (_phoneView == nil) {
        _phoneView = [[UIView alloc] init];
        _phoneView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"690 100 131 Copy"]];
        
    }
    return _phoneView;
}

- (UITextField *)loginPhoneTextField{
    if (_loginPhoneTextField == nil) {
        _loginPhoneTextField = [[UITextField alloc]init];
        _loginPhoneTextField.placeholder = @"手机号";
        _loginPhoneTextField.keyboardType = UIKeyboardTypeNumberPad;
        _loginPhoneTextField.font = [UIFont systemFontOfSize:15];
        _loginPhoneTextField.textColor = [UIColor colorWithHexColor:@"#66666B"];
        //使用KVC给placeholder 赋值
        [_loginPhoneTextField setValue:[UIColor colorWithHexColor:@"#66666B"] forKeyPath:@"_placeholderLabel.textColor"];
        
    }return _loginPhoneTextField;
}

-(UIButton *)openAccountBtn{
    if (_openAccountBtn == nil) {
        _openAccountBtn = [[UIButton alloc] init];
        [_openAccountBtn setTitle:@"开户" forState:UIControlStateNormal];
        _openAccountBtn.titleLabel.font=[UIFont systemFontOfSize:18];
        [_openAccountBtn setTitleColor:[UIColor colorWithHexColor:@"#191A27"] forState:UIControlStateNormal];
        [_openAccountBtn setBackgroundImage:[UIImage imageNamed:@"Rectangle 184"] forState:UIControlStateNormal];
        [_openAccountBtn addTarget:self action:@selector(openAccountBtnDidClick) forControlEvents:UIControlEventTouchUpInside];
    }
    return _openAccountBtn;
}
-(UILabel *)registerLb{
    if (_registerLb == nil) {
        _registerLb = [[UILabel alloc] init];
        _registerLb.text = @"注册即视为同意";
        _registerLb.textColor = [UIColor colorWithHexColor:@"#66666B"];
        _registerLb.font =[UIFont systemFontOfSize:12];
    }
    return _registerLb;
}

-(DDAgreeLb *)agreeLb{
    if (_agreeLb == nil) {
        _agreeLb = [[DDAgreeLb alloc] init];
        _agreeLb.text = @"用户服务协议";
        _agreeLb.textColor = [UIColor colorWithHexColor:@"#DBAA7B"];
        //设置快意用于交互
        _agreeLb.userInteractionEnabled = YES;
        _agreeLb.font =[UIFont systemFontOfSize:12];
    }
    return _agreeLb;
    
    
    
}


@end
